﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region RPTAdmixtureReview

        public List<tb_RPT_AdmixtureReview> GetAllAdmixtureReview()
        {
            var query = (from obj in this.tb_RPT_AdmixtureReviews
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }


        public List<tb_RPT_AdmixtureReview> GetAdmixtureReviewByContition(string strSequence, string strProjectName, string strAdditiveFactor
                                                                    , string strOutSequence, string strInDate, string strTestDate)
        {
            var tq = from obj in this.tb_RPT_AdmixtureReviews
                     where obj.IsDelete == 0
                     select obj;

            if (strSequence.Length > 0)
            {
                tq = tq.Where(entity => entity.Sequence == strSequence);
            }
            if (strProjectName.Length > 0)
            {
                tq = tq.Where(entity => entity.ProjectName == strProjectName);
            }
            if (strAdditiveFactor.Length > 0)
            {
                tq = tq.Where(entity => entity.AdditiveFactor == strAdditiveFactor);
            }
            if (strOutSequence.Length > 0)
            {
                tq = tq.Where(entity => entity.OutSequence == strOutSequence);
            }
            if (strInDate.Length > 0)
            {
                tq = tq.Where(entity => entity.InDate == strInDate);
            }
            if (strTestDate.Length > 0)
            {
                tq = tq.Where(entity => entity.TestDate == strTestDate);
            }
             
            var query = tq.ToList();
            return query;
        }

        public tb_RPT_AdmixtureReview GetAdmixtureReviewById(int id)
        {
            return this.tb_RPT_AdmixtureReviews.SingleOrDefault(tb_RPT_AdmixtureReviews => tb_RPT_AdmixtureReviews.Id == id);
        }

        public void CreateAdmixtureReview(tb_RPT_AdmixtureReview entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_RPT_AdmixtureReviews.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyAdmixtureReview(tb_RPT_AdmixtureReview entity)
        {
            tb_RPT_AdmixtureReview instance = this.tb_RPT_AdmixtureReviews.SingleOrDefault(p => p.Id == entity.Id);
            instance.Sequence = entity.Sequence;
            instance.ProjectName = entity.ProjectName;
            instance.AdditiveFactor = entity.AdditiveFactor;
            instance.OutSequence = entity.OutSequence;
            instance.InDate = entity.InDate;
            instance.TestDate = entity.TestDate;
            instance.CONTROLAppearance = entity.CONTROLAppearance;
            instance.CONTROLSolid = entity.CONTROLSolid;
            instance.CONTROLDensity = entity.CONTROLDensity;
            instance.CONTROLPH = entity.CONTROLPH;
            instance.CONTROLPulpFlowDegree = entity.CONTROLPulpFlowDegree;
            instance.CONTROLChlorineIon = entity.CONTROLChlorineIon;
            instance.MEASUAppearance = entity.MEASUAppearance;
            instance.MEASUSolid = entity.MEASUSolid;
            instance.MEASUDensity = entity.MEASUDensity;
            instance.MEASUPH = entity.MEASUPH;
            instance.MEASUPulpFlowDegree = entity.MEASUPulpFlowDegree;
            instance.MEASUChlorineIon = entity.MEASUChlorineIon;
            instance.TestStandard = entity.TestStandard;
            instance.TestResult = entity.TestResult;
            instance.Remark = entity.Remark;
            instance.Review = entity.Review;
            instance.Approval = entity.Approval;
            instance.Test = entity.Test; 

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }

        public void DeleteAdmixtureReview(tb_RPT_AdmixtureReview entity)
        {
            tb_RPT_AdmixtureReview deleteEntity = tb_RPT_AdmixtureReviews.SingleOrDefault(p => p.Id == entity.Id);
            tb_RPT_AdmixtureReviews.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }
}
